/**********************************************
/ file : constellation_mapping.sc
/ Author : Jungmin Park
/ Date : 4/25/2011 
/ Specification Model of Constellation mapping 
***********************************************/
#include <stdio.h>
import "c_double_handshake";

behavior Constellation_mapping (i_receiver IR, i_sender IS1, i_sender IS2)
{
      char temp [8];
      char temp1; 
	int i, j;
	float v1, v2;
	
 void main (void)
 {
  while (1) {
    for (i=0; i<8; i++)
    {   
      IR.receive (temp+i, sizeof(char));
     } 

    for (i=0; i<8; i++) 
    {
      for (j=0; j<2; j++) 
      {         	
	  if ( j >= 1) 
	    temp1 = temp[i] & 0x0f; 
	  else 
	    temp1 = (temp[i] & 0xf0) >> 4;
     	  switch( temp1 ) 
	  {
         case 0:
               v1 = 1;  
		   v2 = 1; 
		   break; 
	   case 1:
		   v1 = 1;
		   v2 = 3;
		   break;
	   case 2:
		   v1 = 3;  
		   v2 = 1; 
		   break; 
	   case 3:
		   v1 = 3;
		   v2 = 3;
		   break; 
         case 4:
		   v1 = 1;  
		   v2 = -1; 
		   break; 
	   case 5:
		   v1 = 1;
		   v2 = -3;
		   break;
	   case 6:
		   v1 = 3;  
		   v2 = -1; 
		   break; 
	   case 7:
		   v1 = 3;
		   v2 = -3;
		   break; 
         case 8:
		   v1 = -1;  
		   v2 = 1; 
		   break; 
	   case 9:
		   v1 = -1;
		   v2 = 3;
		   break;
	   case 10:
		   v1 = -3;  
		   v2 = 1; 
		   break; 
	   case 11:
		   v1 = -3;
		   v2 = 3;
		   break; 
         case 12:
		   v1 = -1;  
		   v2 = -1; 
		   break; 
	   case 13:
		   v1 = -1;
		   v2 = -3;
		   break;
	   case 14:
		   v1 = -3;  
		   v2 = -1; 
		   break; 
	   case 15:
		   v1 = -3;
		   v2 = -3;
		   break; 
	   } // end switch
    	   IS1.send (&v1, sizeof(v1));
	   IS2.send (&v2, sizeof(v1));
        } //end for
      } // end for
    }
  } // end main
};
